Made cargo derive more working directory locations from its Config
authorMarvin Löbel <loebel.marvin@gmail.com>
Fri, 16 Oct 2015 12:54:40 +0000 (14:54 +0200)
committerMarvin Löbel <loebel.marvin@gmail.com>
Wed, 28 Oct 2015 11:15:37 +0000 (12:15 +0100)
26 files changed:
src/bin/bench.rs
src/bin/build.rs
src/bin/clean.rs
src/bin/doc.rs
src/bin/fetch.rs
src/bin/generate_lockfile.rs
src/bin/locate_project.rs
src/bin/package.rs
src/bin/pkgid.rs
src/bin/publish.rs
src/bin/read_manifest.rs
src/bin/run.rs
src/bin/rustc.rs
src/bin/test.rs
src/bin/update.rs
src/bin/verify_project.rs
src/cargo/lib.rs
src/cargo/ops/cargo_new.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/engine.rs
src/cargo/ops/registry.rs
src/cargo/util/config.rs
src/cargo/util/important_paths.rs
src/cargo/util/process_builder.rs
src/cargo/util/rustc.rs
src/cargo/util/vcs.rs

index 7e658997d285a10b86ad9dcce1c2ad800f2b073f..4dc080a42c7e7f5d2a3fc771a029919e3219809d 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Human, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -62,7 +62,7 @@ Compilation can be customized with the `bench` profile in the manifest.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
index 27bcf57b122e1c5443e26f0178e6adaf30c573d1..c291ba9c78a3f3a0473fda601a34d92c6cb7baab 100644 (file)
@@ -2,7 +2,7 @@ use std::env;
 
 use cargo::ops::CompileOptions;
 use cargo::ops;
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 use cargo::util::{CliResult, CliError, Config};
 
 #[derive(RustcDecodable)]
@@ -64,7 +64,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let opts = CompileOptions {
         config: config,
index 8aea04d35a70cc0eeb442549cc09c47a55bf9694..c06d657fefb2c696366d54eeae9e9ead8fb2ff14 100644 (file)
@@ -2,7 +2,7 @@ use std::env;
 
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -40,7 +40,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
     debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
     let opts = ops::CleanOptions {
         config: config,
         spec: &options.flag_package,
index 16fd12430ecdb5e2f710443bb84b485c90a8b3a9..63a539ae6e4b8a1d837c4dfa4ece87aa82560503 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -52,7 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let mut doc_opts = ops::DocOptions {
         open_result: options.flag_open,
index 6b2cb9d91a882aab7b2cde3cdf809847e87595f9..c9737571f076ee648ad84a7f6810c14d20db9f7f 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -36,7 +36,7 @@ all updated.
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
     try!(ops::fetch(&root, config).map_err(|e| {
         CliError::from_boxed(e, 101)
     }));
index 29891f1c846f84e7419089dfc6f92aec10447571..1e006bdf3344dda53fe4336acbb8f0b10121ae76 100644 (file)
@@ -2,7 +2,7 @@ use std::env;
 
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -30,7 +30,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     ops::generate_lockfile(&root, config)
         .map(|_| None).map_err(|err| CliError::from_boxed(err, 101))
index 4c870ba4de2ea6dafc57c4c7067257228f3cae13..e9fb4345401c0234e95d85821c1c9281cab09490 100644 (file)
@@ -1,5 +1,5 @@
 use cargo::util::{CliResult, CliError, human, ChainError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct LocateProjectFlags {
@@ -21,8 +21,8 @@ struct ProjectLocation {
 }
 
 pub fn execute(flags: LocateProjectFlags,
-               _: &Config) -> CliResult<Option<ProjectLocation>> {
-    let root = try!(find_root_manifest_for_cwd(flags.flag_manifest_path));
+               config: &Config) -> CliResult<Option<ProjectLocation>> {
+    let root = try!(find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd()));
 
     let string = try!(root.to_str()
                       .chain_error(|| human("Your project path contains \
index 4d3b72b716ad7ca129601151e7b59e47b06735ce..63edc3baed89d7e142315a6761b8d88e6e321433 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -34,7 +34,7 @@ Options:
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
     ops::package(&root, config,
                  !options.flag_no_verify,
                  options.flag_list,
index abbe4e52fc7e1b9d83cf871da00b70f7f3317c91..b95294e0c8254a59eecc74df6665e7bd7d6d71bb 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -49,7 +49,7 @@ pub fn execute(options: Options,
                config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path.clone()));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path.clone(), config.cwd()));
 
     let spec = options.arg_spec.as_ref().map(|s| &s[..]);
     let spec = try!(ops::pkgid(&root, spec, config).map_err(|err| {
index 387daecd2353fc921fa6cb0dedfe779351094eed..d70043c0c510673ee3c87fcc0e18f54b2ff6d8b8 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -42,7 +42,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
         ..
     } = options;
 
-    let root = try!(find_root_manifest_for_cwd(flag_manifest_path.clone()));
+    let root = try!(find_root_manifest_for_wd(flag_manifest_path.clone(), config.cwd()));
     ops::publish(&root, config, token, host, !no_verify).map(|_| None).map_err(|err| {
         CliError::from_boxed(err, 101)
     })
index 2539655f859d62f86f6be683f4e725036920c973..b25eedb0e5d76fe4a07735b2e6b5127a6fedb003 100644 (file)
@@ -3,7 +3,7 @@ use std::error::Error;
 
 use cargo::core::{Package, Source};
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 use cargo::sources::{PathSource};
 
 #[derive(RustcDecodable)]
@@ -29,7 +29,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<Package>>
            env::args().collect::<Vec<_>>());
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let mut source = try!(PathSource::for_path(root.parent().unwrap(), config).map_err(|e| {
         CliError::new(e.description(), 1)
index d765967ddda8ae2fa8588ab407b5e9b533bb838f..f05d63e3d485eeb11756d3c81b683842566a2ca9 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config, Human};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -52,7 +52,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let (mut examples, mut bins) = (Vec::new(), Vec::new());
     if let Some(s) = options.flag_bin {
index 924cfb6365e142111f3e12739320880a14bae23e..72b8f71a5dbd5107ae036cda132f56382841df70 100644 (file)
@@ -2,7 +2,7 @@ use std::env;
 
 use cargo::ops::CompileOptions;
 use cargo::ops;
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 use cargo::util::{CliResult, CliError, Config};
 
 #[derive(RustcDecodable)]
@@ -67,7 +67,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let opts = CompileOptions {
         config: config,
index 09981e0bed8541bc8eba2cbb997d05cb87f43930..2029daa4c021edd6fa5f879ccc5fd8898335bb03 100644 (file)
@@ -1,6 +1,6 @@
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Human, Config};
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -68,7 +68,7 @@ Compilation can be configured via the `test` profile in the manifest.
 ";
 
 pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
 
index 75cac7a70efbf4baa286409fe6116798973529fa..27842ba8d4c0b0f4b4210718170af02116cb3e5c 100644 (file)
@@ -2,7 +2,7 @@ use std::env;
 
 use cargo::ops;
 use cargo::util::{CliResult, CliError, Config};
-use cargo::util::important_paths::find_root_manifest_for_cwd;
+use cargo::util::important_paths::find_root_manifest_for_wd;
 
 #[derive(RustcDecodable)]
 struct Options {
@@ -56,7 +56,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
     debug!("executing; cmd=cargo-update; args={:?}", env::args().collect::<Vec<_>>());
     try!(config.shell().set_verbosity(options.flag_verbose, options.flag_quiet));
     try!(config.shell().set_color_config(options.flag_color.as_ref().map(|s| &s[..])));
-    let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
+    let root = try!(find_root_manifest_for_wd(options.flag_manifest_path, config.cwd()));
 
     let update_opts = ops::UpdateOptions {
         aggressive: options.flag_aggressive,
index b4998282e1dccf578e013595bd9df6a53cc4bca3..962a0340f0dce178c51a544431e3ae7b4f7d8091 100644 (file)
@@ -3,7 +3,7 @@ use std::fs::File;
 use std::io::prelude::*;
 use std::process;
 
-use cargo::util::important_paths::{find_root_manifest_for_cwd};
+use cargo::util::important_paths::{find_root_manifest_for_wd};
 use cargo::util::{CliResult, Config};
 use rustc_serialize::json;
 use toml;
@@ -37,7 +37,7 @@ pub fn execute(args: Flags, config: &Config) -> CliResult<Option<Error>> {
 
     let mut contents = String::new();
     let filename = args.flag_manifest_path.unwrap_or("Cargo.toml".into());
-    let filename = match find_root_manifest_for_cwd(Some(filename)) {
+    let filename = match find_root_manifest_for_wd(Some(filename), config.cwd()) {
         Ok(manifest_path) => manifest_path,
         Err(e) => fail("invalid", &e.to_string()),
     };
index 949e3c0e6fa5ce85623cc997069207cf07974556..1c85c686b66ed4743e2ee9dc2b907fb88e1c20eb 100644 (file)
@@ -97,7 +97,10 @@ fn process<V, F>(mut callback: F)
 {
     let mut config = None;
     let result = (|| {
-        config = Some(try!(Config::new(shell(Verbose, Auto))));
+        let cwd = try!(env::current_dir().chain_error(|| {
+            human("couldn't get the current directory of the process")
+        }));
+        config = Some(try!(Config::new(shell(Verbose, Auto), cwd)));
         let args: Vec<_> = try!(env::args_os().map(|s| {
             s.into_string().map_err(|s| {
                 human(format!("invalid unicode in argument: {:?}", s))
index c3a6e5acb555bebfd09f39bda642a401e2cc85f4..f64929a1f142790636312ec76dab6786620221d2 100644 (file)
@@ -97,15 +97,15 @@ fn strip_rust_affixes(name: &str) -> &str {
     name
 }
 
-fn existing_vcs_repo(path: &Path) -> bool {
-    GitRepo::discover(path).is_ok() || HgRepo::discover(path).is_ok()
+fn existing_vcs_repo(path: &Path, cwd: &Path) -> bool {
+    GitRepo::discover(path, cwd).is_ok() || HgRepo::discover(path, cwd).is_ok()
 }
 
 fn mk(config: &Config, path: &Path, name: &str,
       opts: &NewOptions) -> CargoResult<()> {
     let cfg = try!(global_config(config));
     let mut ignore = "target\n".to_string();
-    let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap());
+    let in_existing_vcs_repo = existing_vcs_repo(path.parent().unwrap(), config.cwd());
     if !opts.bin {
         ignore.push_str("Cargo.lock\n");
     }
@@ -119,11 +119,11 @@ fn mk(config: &Config, path: &Path, name: &str,
 
     match vcs {
         VersionControl::Git => {
-            try!(GitRepo::init(path));
+            try!(GitRepo::init(path, config.cwd()));
             try!(paths::write(&path.join(".gitignore"), ignore.as_bytes()));
         },
         VersionControl::Hg => {
-            try!(HgRepo::init(path));
+            try!(HgRepo::init(path, config.cwd()));
             try!(paths::write(&path.join(".hgignore"), ignore.as_bytes()));
         },
         VersionControl::NoVcs => {
index 89a2c1a08ecf2d1c3b5af09ca0d931e8b0f34d36..caf5301d0dbb060a35a853b6240918a6516174c1 100644 (file)
@@ -100,7 +100,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
     /// specified as well as the exe suffix
     fn filename_parts(target: Option<&str>, cfg: &Config)
                       -> CargoResult<(Option<(String, String)>, String)> {
-        let mut process = try!(util::process(cfg.rustc()));
+        let mut process = try!(util::process(cfg.rustc(), cfg.cwd()));
         process.arg("-")
                .arg("--crate-name").arg("_")
                .arg("--crate-type").arg("dylib")
index 41a3188bbf5c309685d0dbe997ec0cae88ef87f8..2ce00296284b1c26666eb2a1c04f86eeef137389 100644 (file)
@@ -40,10 +40,10 @@ impl CommandPrototype {
                -> CargoResult<CommandPrototype> {
         Ok(CommandPrototype {
             builder: try!(match ty {
-                CommandType::Rustc => process(config.rustc()),
-                CommandType::Rustdoc => process(config.rustdoc()),
+                CommandType::Rustc => process(config.rustc(), config.cwd()),
+                CommandType::Rustdoc => process(config.rustdoc(), config.cwd()),
                 CommandType::Target(ref s) |
-                CommandType::Host(ref s) => process(s),
+                CommandType::Host(ref s) => process(s, config.cwd()),
             }),
             ty: ty,
         })
index 75ee24c2d15dc5d7ee873feb046636b16a394dd9..f9b6bf52bf733356adacf39c94c35354fa89b87b 100644 (file)
@@ -20,7 +20,7 @@ use util::config;
 use util::paths;
 use util::{CargoResult, human, ChainError, ToUrl};
 use util::config::{Config, ConfigValue, Location};
-use util::important_paths::find_root_manifest_for_cwd;
+use util::important_paths::find_root_manifest_for_wd;
 
 pub struct RegistryConfig {
     pub index: Option<String>,
@@ -252,7 +252,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
     let name = match opts.krate {
         Some(ref name) => name.clone(),
         None => {
-            let manifest_path = try!(find_root_manifest_for_cwd(None));
+            let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd()));
             let pkg = try!(Package::for_path(&manifest_path, config));
             pkg.name().to_string()
         }
@@ -312,7 +312,7 @@ pub fn yank(config: &Config,
     let name = match krate {
         Some(name) => name,
         None => {
-            let manifest_path = try!(find_root_manifest_for_cwd(None));
+            let manifest_path = try!(find_root_manifest_for_wd(None, config.cwd()));
             let pkg = try!(Package::for_path(&manifest_path, config));
             pkg.name().to_string()
         }
index de5302f6fdda397cd5b1766df37360ca8acdf0aa..8b2b09efc1b50c874839bba4fdfc4ab12229003e 100644 (file)
@@ -31,11 +31,7 @@ pub struct Config {
 }
 
 impl Config {
-    pub fn new(shell: MultiShell) -> CargoResult<Config> {
-        let cwd = try!(env::current_dir().chain_error(|| {
-            human("couldn't get the current directory of the process")
-        }));
-
+    pub fn new(shell: MultiShell, cwd: PathBuf) -> CargoResult<Config> {
         let mut cfg = Config {
             home_path: try!(homedir(cwd.as_path()).chain_error(|| {
                 human("Cargo couldn't find your home directory. \
@@ -231,7 +227,7 @@ impl Config {
     }
 
     fn scrape_rustc_version(&mut self) -> CargoResult<()> {
-        self.rustc_info = try!(Rustc::new(&self.rustc));
+        self.rustc_info = try!(Rustc::new(&self.rustc, self.cwd()));
         Ok(())
     }
 
index 1d6076b4b875c8fa923da2ee6a7776bdc79b12f0..bca7fc3c2f0c08d86d70319493fee513de25c2fc 100644 (file)
@@ -1,7 +1,6 @@
-use std::env;
 use std::fs;
 use std::path::{Path, PathBuf};
-use util::{CargoResult, human, ChainError};
+use util::{CargoResult, human};
 
 /// Iteratively search for `file` in `pwd` and its parents, returning
 /// the path of the directory.
@@ -35,11 +34,8 @@ pub fn find_project_manifest(pwd: &Path, file: &str) -> CargoResult<PathBuf> {
 }
 
 /// Find the root Cargo.toml
-pub fn find_root_manifest_for_cwd(manifest_path: Option<String>)
+pub fn find_root_manifest_for_wd(manifest_path: Option<String>, cwd: &Path)
                                   -> CargoResult<PathBuf> {
-    let cwd = try!(env::current_dir().chain_error(|| {
-        human("Couldn't determine the current working directory")
-    }));
     match manifest_path {
         Some(path) => {
             let absolute_path = cwd.join(&path);
index 628b681c1f1dad0877938a19adc220269d44affb..08003de696c391a25965219d6dcb6cfe38e6fe1e 100644 (file)
@@ -60,7 +60,9 @@ impl ProcessBuilder {
     pub fn get_args(&self) -> &[OsString] {
         &self.args
     }
-    pub fn get_cwd(&self) -> &Path { Path::new(&self.cwd) }
+    pub fn get_cwd(&self) -> &Path {
+        Path::new(&self.cwd)
+    }
 
     pub fn get_env(&self, var: &str) -> Option<OsString> {
         self.env.get(var).cloned().or_else(|| Some(env::var_os(var)))
@@ -106,7 +108,7 @@ impl ProcessBuilder {
 
     pub fn build_command(&self) -> Command {
         let mut command = Command::new(&self.program);
-        command.current_dir(&self.cwd);
+        command.current_dir(&self.get_cwd());
         for arg in self.args.iter() {
             command.arg(arg);
         }
@@ -129,11 +131,11 @@ impl ProcessBuilder {
     }
 }
 
-pub fn process<T: AsRef<OsStr>>(cmd: T) -> CargoResult<ProcessBuilder> {
+pub fn process<T: AsRef<OsStr>, U: AsRef<OsStr>>(cmd: T, cwd: U) -> CargoResult<ProcessBuilder> {
     Ok(ProcessBuilder {
         program: cmd.as_ref().to_os_string(),
         args: Vec::new(),
-        cwd: try!(env::current_dir()).as_os_str().to_os_string(),
+        cwd: cwd.as_ref().to_os_string(),
         env: HashMap::new(),
     })
 }
index 0a3fbf69b03516cc96592e40d28b698f9a01586e..a0cb1720f461ece9d14c3df00ade1e9a7ee86b79 100644 (file)
@@ -14,8 +14,8 @@ impl Rustc {
     ///
     /// If successful this function returns a description of the compiler along
     /// with a list of its capabilities.
-    pub fn new<P: AsRef<Path>>(path: P) -> CargoResult<Rustc> {
-        let mut cmd = try!(util::process(path.as_ref()));
+    pub fn new<P: AsRef<Path>>(path: P, cwd: &Path) -> CargoResult<Rustc> {
+        let mut cmd = try!(util::process(path.as_ref(), cwd));
         cmd.arg("-vV");
 
         let mut ret = Rustc::blank();
index d171ec5eb3c0cad0774f09e1e960b64cc0470f16..cad07c53bb1d9b0b345038d4ed03d6be54d33cf4 100644 (file)
@@ -8,22 +8,22 @@ pub struct HgRepo;
 pub struct GitRepo;
 
 impl GitRepo {
-    pub fn init(path: &Path) -> CargoResult<GitRepo> {
+    pub fn init(path: &Path, _: &Path) -> CargoResult<GitRepo> {
         try!(git2::Repository::init(path));
         return Ok(GitRepo)
     }
-    pub fn discover(path: &Path) -> Result<git2::Repository,git2::Error> {
+    pub fn discover(path: &Path, _: &Path) -> Result<git2::Repository,git2::Error> {
         git2::Repository::discover(path)
     }
 }
 
 impl HgRepo {
-    pub fn init(path: &Path) -> CargoResult<HgRepo> {
-        try!(try!(process("hg")).arg("init").arg(path).exec());
+    pub fn init(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
+        try!(try!(process("hg", cwd)).arg("init").arg(path).exec());
         return Ok(HgRepo)
     }
-    pub fn discover(path: &Path) -> CargoResult<HgRepo> {
-        try!(try!(process("hg")).arg("root").cwd(path).exec_with_output());
+    pub fn discover(path: &Path, cwd: &Path) -> CargoResult<HgRepo> {
+        try!(try!(process("hg", cwd)).arg("root").cwd(path).exec_with_output());
         return Ok(HgRepo)
     }
 }